/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objects;

import graphic.Color;
import OBJ_Loader.Object;
import graphic.Graphic;
import graphic.TownConfig;
import graphic.WorldConfig;
import java.util.HashMap;
/**
 *
 * @author nicra
 */
public class Town {
    public Color col;
    
    public Mill mill;
    public Estate estate;
    
    public Type selected=Type.NOTHING;
    
    public float sizex,stx;
    public float sizez,sty;
    public float rot;
    
    public Dir corner;
    
    public HashMap<Type,SRect> list = new HashMap<>();
    public HashMap<Type,Integer> lvlList = new HashMap<>();
    
    public Type select(float x, float y){
        if(list.get(Type.MILL).in(x, y)) selected =  Type.MILL;
        else if(list.get(Type.ESTATE).in(x, y)) selected = Type.ESTATE;
        else selected = Type.NOTHING;
        return selected;
    }
    
    public Town(Dir corn, Color col){
        sizex=WorldConfig.X_SIZE/2-WorldConfig.PATH_WIDTH+1;
        sizez=WorldConfig.Y_SIZE/2-WorldConfig.PATH_WIDTH+1;
        this.col = col;
        corner=corn;
        switch(corner){
            case UPLEFT:
                stx=WorldConfig.X_SIZE/2;
                sty=-WorldConfig.Y_SIZE/2+sizez;
                rot=0;
                break;
            case UPRIGHT:
                stx=-WorldConfig.X_SIZE/2+sizex;
                sty=-WorldConfig.Y_SIZE/2+sizez;
                rot=90;
                break;
            case DOWNLEFT:
                stx=WorldConfig.X_SIZE/2;
                sty=WorldConfig.Y_SIZE/2;
                rot=180;
                break;
            case DOWNRIGHT:
                stx=-WorldConfig.X_SIZE/2+sizex;
                sty=WorldConfig.Y_SIZE/2;
                rot=270;
                break;
        }
        
        mill = new Mill(stx-TownConfig.MILL_X*sizex,0,sty-TownConfig.MILL_Y*sizez,0.5f);
        estate = new Estate(stx-TownConfig.ESTATE_X*sizex,sty-TownConfig.ESTATE_Y*sizez,
                stx-TownConfig.ESTATE_MX*sizex,sty-TownConfig.ESTATE_MY*sizez,4f);
        mill.setRot(rot+2);
        
        list.put(Type.MILL, mill.getRect());
        list.put(Type.ESTATE, estate.getRect());
        lvlList.put(Type.MILL, 1);
        lvlList.put(Type.ESTATE, 1);
        
    }
    public void draw(){
        Graphic.e.setColor(col);
        mill.draw();
        estate.draw();
        
        if(selected!=Type.NOTHING){
            Graphic.e.setColor(new Color(1,1,1,1));
            list.get(selected).draw();
        }
    }

    public String getSLvl() {
        if(selected!=Type.NOTHING){
            return "Poziom "+lvlList.get(selected).toString();
        }
        return "";
    }
    
}
